
        <script type="text/javascript" src="<?php echo $this->module->assetsUrl; ?>/datepicker/WdatePicker.js" /></script>


<style type="text/css">
    
div.form label.labelForRadio 
{
    display:inline-block;
    width:auto;float:none;
}
</style>
 
  

<div class="container-fluid">

    <div class="row-fluid">
        <div class="span12">
            <h3 class="page-title">
                活动管理 <small>抽奖设置</small>
            </h3>
            <ul class="breadcrumb">
                <li>
                    <i class="icon-home"></i>
                    <a href="javascript:;">活动管理</a> 
                    <i class="icon-angle-right"></i>
                </li>
                <li class="active"><a href="javascript:;">抽奖设置</a></li>

            </ul>
            <!-- END PAGE TITLE & BREADCRUMB-->
        </div>
    </div>
    
     <div class="row-fluid">
        <div class="span12">
                <button  type="button"  onclick="history.go(-1)"  class="btn blue" >返回活动列表</button>
          </div>
    </div>
    
    
    
   

    <div class="row-fluid">
        <div class="span12">
<!--BEGIN TABS-->
            <div class="tabbable tabbable-custom tabbable-full-width">
                <div class="tab-content">
                    <div class="portlet box blue">
                        <div class="portlet-title">
                                <div class="caption"><i class="icon-reorder"></i>抽奖设置</div>
                                 <div class="actions">
                                         <button  data-toggle="modal" data-target="#add" class="btn red"><i class="icon-pencil"></i>新增抽奖</button>
                                         
                                </div>   
                        </div>
                        <div class="portlet-body form">
                                    <?php
            $this->widget('bootstrap.widgets.TbGridView', array(
                'id' => 'table-lottery',
                'dataProvider' =>$ActivityLinkLottery->search($activity_id),
                'filter' => $ActivityLinkLottery,
              //  'enableHistory' =>'true',
                  'ajaxUpdate'=>'info',
                'htmlOptions' =>array('class'=>'table table-hover'),              
               // 'afterAjaxUpdate' => 'reinstallDatePicker',
                'summaryText' => '<font color="#0066A4"; style="float:right;">显示{start}-{end}条.共{count}条记录,当前第{page}页</font>', 
                'columns' => array(
                    array(
                        'name' => 'id',
                        'value' => '$data->id',
                        'headerHtmlOptions' =>array('style'=>'width:50px;'),
                       
                    ),
                     array(
                        'name' => 'lottery_num',
                         'header'=>'中奖人数',
                        'value' => '$data->lottery_num',
                      //  'headerHtmlOptions' =>array('style'=>'width:50px;'),
                       
                    ),
                  
                     array(
                        'name' => 'lottery_start_time',
                        'header'=>'抽奖开始时间',
                        'value' => '$data->lottery_start_time?date("Y-m-d H:i:s",$data->lottery_start_time):0',
                        'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'model' => $ActivityLinkLottery,
                            'attribute' => 'lottery_start_time',
                            'language' => 'zh',              
                            'htmlOptions' => array(
                                'id' => 'datepicker_for_due_date',                       
                                'style' => 'height:20px;width:80px;',
                            ),
                            'options' => array(// 
                                'showAnim' =>'slideDown',
                                'dateFormat' => 'yy-mm-dd',
                                'showButtonPanel' => true,
                            )
                                ), true), //
                    ),
                    
                      array(
                        'name' => 'lottery_end_time',
                        'header'=>'抽奖结束时间',
                        'value' => '$data->lottery_end_time?date("Y-m-d H:i:s",$data->lottery_end_time):0',
                         'filter' => $this->widget('zii.widgets.jui.CJuiDatePicker', array(
                            'model' => $ActivityLinkLottery,
                            'attribute' => 'lottery_end_time',
                            'language' => 'zh',              
                            'htmlOptions' => array(
                                'id' => 'datepicker_for_due_date1',                       
                                'style' => 'height:20px;width:80px;',
                            ),
                            'options' => array(// 
                                'showAnim' =>'slideDown',
                                'dateFormat' => 'yy-mm-dd',
                                 'firstDay'=>1,
                                'showButtonPanel' => true,
                            )
                                ), true), //
                    ),
                    array(
                        'name' => 'status',
                        'header'=>'是否开始',
                        'value' => '$data->status==1?"开始":""',
                        'filter'=>array('1'=>'是','0'=>'否'),
                        'headerHtmlOptions' =>array('style'=>'width:50px;'),
                    ),
                   
                    array(
                   'header' => '操作',
                   'class' => 'bootstrap.widgets.TbButtonColumn',


                   'template' =>'{chakan}|{lottery}|{lottery_end}',

                  'htmlOptions' =>array('style'=>'width:220px;'),
                   'buttons' => array(
                       'chakan' => array(
                           'label' => '查看中奖',
                           'url' => 'Yii::app()->createUrl("xyhadm/activity/lotteryview",
                                   array(
                                           "id"=>$data->id,
                                           "activity_id"=>$data->activity_id,
                                           "end_time"=>$data->lottery_end_time,
                                          
                                        ))',
                          'options' => array(
                                    'data-toggle' => 'modal',
                                    'data-target' => '#view', 
                                    'class'=>'label label-success'
                           ),
                         ),

                        //'edit' =>'$data->is_edit($data->type_id)',
                      
                
                           'lottery'=>array(
                           'label' =>'抽奖开始',
                           'url' =>'"javascript:lottery_start(\"".$data->activity_id."\",\"".$data->id."\",\"".$data->lottery_start_time."\",\"".$data->lottery_end_time."\",\"".$data->status."\");"',
                           'options'=>array('class'=>'btn red mini')

                       ),
                       
                            'lottery_end'=>array(
                           'label' =>'抽奖结束',
                           'url' =>'"javascript:lottery_end(\"".$data->activity_id."\",\"".$data->id."\",\"".$data->lottery_start_time."\",\"".$data->lottery_end_time."\",\"".$data->status."\",\"".$data->lottery_num."\");"',
                           'options'=>array('class'=>'btn bule mini')

                       ),
                   
                       
//                        'hotCancel'=>array(
//                           'label' =>'取消热点',
//                           'url' =>   '"javascript:hot(\"".$data->id."\",\"".$data->is_hot."\");"',
//                           'options'=>array('class'=>'btn blue mini')
//                       )

                       ),        
                   ),
                    
                    
                    
                    
           
               
               ),
                
            ));
  Yii::app()->clientScript->registerScript('re-install-date-picker',"
            function reinstallDatePicker(id, data){ 
                $('#datepicker_for_due_date').datepicker(jQuery.extend(jQuery.datepicker.regional['en'],{'dateFormat':'yy-mm-dd'}));//
                $('#datepicker_for_due_date1').datepicker(jQuery.extend(jQuery.datepicker.regional['en'],{'dateFormat':'yy-mm-dd'}));//
               
}");
                  
            
            ?> 
                             
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>   

    
</div>
            






<div class="modal fade"  id="add" style="display: none;" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
   <div class="modal-dialog">
        <div class="modal-content">
                <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
                        <h3>新增抽奖</h3>
                </div>
            <div class="modal-body">
                  <?php
                        $form = $this->beginWidget(
                                      'CActiveForm', array(
                                  'id' => 'lottery-form',
                                // 'enableAjaxValidation'=>true,   
                                 'enableClientValidation'=>true,     
                                  'clientOptions' => array(  
                                        'validateOnSubmit' => true,  
                                        'afterValidate'=>'js:function(form,data,hasError){  
                                        if(!hasError){  
                                                $.ajax({  
                                                        "type":"POST",  
                                                        "url":"'.Yii::app()->createUrl(Yii::app()->params['adminUrl'].'/activity/lotteryadd').'",
                                                        "data":$("#lottery-form").serialize(), 
                                                        "dataType": "json",
                                                        "success":function(data){
                                                                if(data.status){
                                                                    alert("抽奖添加成功！");
                                                                    $("#table-lottery").yiiGridView("update");
                                                                   $("#add").modal("hide");
                                                                }else{
                                                                    console.log(data);
                                                                    alert("添加失败!失败信息:"+data.error);
                                                                }
                                                            },  
                                                        });  
                                                }  
                                        }'  
                                    ),          
        
                                  'htmlOptions' => array('enctype' => 'multipart/form-data', 'class' => 'form-horizontal'),
                                      // 'action'=>array('/admin'),
                              ));
                      ?>	
               
               <input type="hidden" id="ActivityLinkLottery_activity_id" name="ActivityLinkLottery[activity_id]" value="<?php echo $activity_id; ?>">            
                                    <div class="control-group">
                                           <label class="control-label">中奖人数</label>
                                           <div class="controls">
                                               <?php echo $form->textField($ActivityLinkLottery,'lottery_num',array('class'=>'m-wrap','placeholder'=>"抽奖人数"))?>
                                               <?php echo $form->error($ActivityLinkLottery, 'lottery_num', array('class' => 'label label-danger')); ?>
                                                   <button type="submit"  class="btn blue"><i class="icon-time"></i>添加抽奖</button>
                                               
                                           </div>
                                       
                                    </div>         
                   
            <?php $this->endWidget(); ?>
          
        </div>
         
                
                
            </div>
            
        </div>
     </div>
</div>  

<div class="modal fade" style="display: none;" id="view"  tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
   <div class="modal-dialog">
        <div class="modal-content" id="prepaidData-content">
               
            
        </div>      
    </div>  
</div>

<script type="text/javascript">

 function lottery_start(activity_id,id,start_time,end_time,status){
     if(status=='2'){//抽奖开始
        if(end_time !='0'){
            alert('活动已结束!');
             return false;
        }    
        
            $.fn.yiiGridView.update('table-lottery',{
            type:'POST',
            url:$(this).attr('href'), 
            data:{'activity_id':activity_id,'id':id,'status':1},
            success:function(data){
                        if(data){
                            $("#table-lottery").yiiGridView("update");
                        }else{
                           
                            alert("请先结束已开始的活动!");
                        }
                    }   
                });
     }else{//抽奖已开始
         
        if(end_time !='0'){
            alert('活动已结束!');
             return false;
        }    
        alert('活动已开始!');
         return false;    
     }
  
    }
    
    function lottery_end(activity_id,id,start_time,end_time,status,num){
     if(status=='1'){//抽奖开始
            $.fn.yiiGridView.update('table-lottery',{
            type:'POST',
            url:$(this).attr('href'), 
            data:{'activity_id':activity_id,'id':id,'status':0,'num':num},
             success:function(data){
                        if(data==0){
                            alert("数据出错!");
                        }
                        else {
                             console.log(data);
                            $("#table-lottery").yiiGridView("update");
                           
                        }
                       
                           
                    } 
                    
                });
   
     }else{//抽奖已开始
         
//        if(end_time !='0'){
//            alert('活动已结束!');
//             return false;
//        }    
        alert('请先开始活动!');
         return false;
          
     }
     
      
    }

$('#view').on('hidden.bs.modal',function(e){
    $('div.modal-backdrop.fade.in').remove();
     history.go(0);
});






</script>